<?php
include("mysqlcon.php");
include("ok.php");
include("error.php");
include("userid.php");

   $room_id = $_GET[roomID];
	echo $overall_price = $_POST[overall_price];
	echo $cash = $_POST[cash];
	echo $change = $_POST[change];

	if($error==true) error_page($error_text);
	
	if($error==false){
      mysql_select_db($dbname,$conn);
      mysql_query('SET NAMES utf8');

	$fetch_checkin_data_query = "SELECT checkin_id, customer.id AS cid, customer_name, customer_surname, customer_tel, reservation.reserv_id, UNIX_TIMESTAMP( checkin_time ) AS checkin_time
FROM checkin
INNER JOIN reservation ON ( checkin.reserv_id = reservation.reserv_id )
INNER JOIN customer ON ( reservation.id = customer.id )
WHERE room_id = '$room_id'";	
	$result = mysql_query($fetch_checkin_data_query,$conn);
	$rs = mysql_fetch_array($result);
	
	$checkin_id = $rs[checkin_id];
	$cid = $rs[cid];
	$customer_name = $rs[customer_name];
	$customer_surname = $rs[customer_surname];
	$customer_tel = $rs[customer_tel];
	$reserv_id = $rs[reserv_id];

	$fetch_room_data_query = "SELECT * FROM resort WHERE room_id = '$room_id'";	
	$result2 = mysql_query($fetch_room_data_query,$conn);
	$rs2 = mysql_fetch_array($result2);

	$roomtype_name = $rs2[roomtype_name];
	$room_cost = $rs2[room_cost];
	
	$checkin_time = $rs[checkin_time];

	$now = mktime();
	//calc time
	$dateDiff = $now - $checkin_time;
	$fullDays = floor($dateDiff/(60*60*24));
	
	$full_checkin_time = date("d/m/Y",$checkin_time);
	$full_now = date("d/m/Y",$now);
	//price calc
	
	//room charge
	$overall_roomprice = $room_cost*$fullDays;
	$overall_price = $overall_roomprice;  
	
	
	
	  //clear room status
	  $clear_room_status = "UPDATE resort SET `room_status` = '0' WHERE `room_id` = '$room_id'";
	  
	  //update reserv status
	  $update_reserv_status = "UPDATE reservation SET `reserv_status` = '5' WHERE `reserv_id` = '$reserv_id'";



      
      if(!mysql_query($update_reserv_status,$conn))
				   error_page("ฐานข้อมูลผิดพลาด $strSQL");
				else 
				{
				   $ok_text = "";
				$printtype = "bill";
				   ok_page("เก็บข้อมูลบิลเรียบร้อย","ระบบทำการ Check-Outและเก็บเงินห้องพักหมายเลข : $room_id เรียบร้อยแล้ว",$ok_text,"admin.php",$ok_text);
				$cash = $_POST[cash];
				$change = $_POST[change];
				}
					   	  //add bill
				$save_bill = "INSERT INTO bill(reserv_id,bill_total,bill_cash,bill_change)";
				$save_bill=$save_bill."VALUES('$reserv_id','$overall_price','$cash','$change')";

				if(!mysql_query($save_bill,$conn))error_page("ฐานข้อมูลผิดพลาด $save_bill");
				if(!mysql_query($clear_room_status,$conn))error_page("ฐานข้อมูลผิดพลาด $clear_room_status");

				mysql_close($conn);
	}
	
    /*$update_reserv_status = "UPDATE reservation SET `reserv_status` = '3' WHERE `reserv_id` = $reserv_id";
    mysql_query($update_reserv_status,$conn);*/
	//
	/*$ok_text = "เลขที่ใบจอง : $reserv_id<br>
	   ชนิดห้องพัก : $roomType<br>
	   ห้องหมายเลข : $roomID<br>
	   ชื่อ-นามสกุล ผู้จอง : $customer_name $customer_surname<br>
	 E-Mail : $customer_email<br>
	 เบอร์โทรศัพท์ : $customer_tel<br>
	 Fax : $customer_fax<br>
	 ระยะเวลาในการพัก : $inputDate<br>";
	   ok_page("จัดเก็บข้อมูลเรียบร้อย","ระบบทำการจัดเก็บข้อมูลการจองแล้ว คุณสามารถสั่งพิมพ์ได้ทันที",$ok_text,"admin.php",$ok_text);
	
	
	<label for='customer_id'>ได้รับเงิน</label> <input type='text' id='customer_id' name='customer_id' value='' size='8' />
	*/
?>

